package com.huawei.hms.auth.api.signin.internal.b;

import com.huawei.hms.support.api.hwid.HuaweiIdSignInOptions;
import com.huawei.hms.support.api.hwid.SignInHuaweiId;
import com.huawei.hms.support.log.HMSLog;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class a {
    private static final a a = new a();
    private Map<String, String> b = new ConcurrentHashMap();

    private a() {
    }

    public static a a() {
        return a;
    }

    public void a(SignInHuaweiId signInHuaweiId, HuaweiIdSignInOptions huaweiIdSignInOptions) {
        String toJson;
        String str = null;
        if (signInHuaweiId != null) {
            try {
                toJson = signInHuaweiId.toJson();
            } catch (Throwable th) {
                HMSLog.e("[HUAWEIIDSDK]LightStorage", "store faild, exception:" + th.getMessage());
                return;
            }
        }
        toJson = null;
        if (huaweiIdSignInOptions != null) {
            str = huaweiIdSignInOptions.toJson();
        }
        a(toJson, str);
    }

    public void a(String str, String str2) {
        this.b.remove("HuaweiIdAccount");
        this.b.remove("HuaweiIdSignInOptions");
        if (str != null) {
            this.b.put("HuaweiIdAccount", str);
        }
        if (str2 != null) {
            this.b.put("HuaweiIdSignInOptions", str2);
        }
    }

    public final SignInHuaweiId b() {
        try {
            String str = (String) this.b.get("HuaweiIdAccount");
            if (str != null) {
                return SignInHuaweiId.fromJson(str);
            }
        } catch (Throwable th) {
            HMSLog.e("[HUAWEIIDSDK]LightStorage", "getHuaweiSignInAccount faild, exception:" + th.getClass().getSimpleName());
        }
        return null;
    }

    public void c() {
        this.b.clear();
    }
}
